package com.keba.lamp.complaint.controller;

import com.keba.basic.annotation.log.WebLog;
import com.keba.basic.base.R;
import com.keba.basic.base.controller.SuperController;
import com.keba.basic.database.mybatis.conditions.Wraps;
import com.keba.basic.database.mybatis.conditions.query.QueryWrap;
import com.keba.basic.interfaces.echo.EchoService;
import com.keba.basic.utils.BeanPlusUtil;
import com.keba.lamp.complaint.entity.EvidenceCaseRel;
import com.keba.lamp.complaint.service.EvidenceCaseRelService;
import com.keba.lamp.complaint.vo.query.EvidenceCaseRelPageQuery;
import com.keba.lamp.complaint.vo.result.EvidenceCaseRelResultVO;
import com.keba.lamp.complaint.vo.save.EvidenceCaseRelSaveVO;
import com.keba.lamp.complaint.vo.update.EvidenceCaseRelUpdateSummarizeVO;
import com.keba.lamp.complaint.vo.update.EvidenceCaseRelUpdateVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * 证据目录和案件关联表
 * </p>
 *
 * @author chaowu.wang
 * @date 2025-04-02 00:12:46
 * @create [2025-04-02 00:12:46] [chaowu.wang] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/evidenceCaseRel")
@Tag(name = "证据目录和案件关联表")
public class EvidenceCaseRelController extends SuperController<EvidenceCaseRelService, Long, EvidenceCaseRel
    , EvidenceCaseRelSaveVO, EvidenceCaseRelUpdateVO, EvidenceCaseRelPageQuery, EvidenceCaseRelResultVO> {
    private final EchoService echoService;
    @Override
    public EchoService getEchoService() {
        return echoService;
    }

    @Override
    public R<List<EvidenceCaseRelResultVO>> query(@RequestBody EvidenceCaseRelPageQuery data) {
        EvidenceCaseRel entity = BeanPlusUtil.toBean(data, getEntityClass());
        QueryWrap<EvidenceCaseRel> wrapper = Wraps.q(entity);
        List<EvidenceCaseRel> list = getSuperService().list(wrapper);
        return success(BeanPlusUtil.toBeanList(list, getResultVOClass()));
    }

    @Operation(summary = "修改证据目录")
    @PostMapping("/updateSummarizeList")
    @WebLog(value = "修改证据目录", request = false)
    public R updateSummarizeList(@Validated @RequestBody List<EvidenceCaseRelUpdateSummarizeVO> summarizeVOList) {
        boolean result = this.superService.updateSummarize(summarizeVOList);
        return result ? R.success() : R.fail("修改失败");
    }

    @Operation(summary = "修改证据目录")
    @PostMapping("/updateSummarize")
    @WebLog(value = "修改证据目录", request = false)
    public R updateSummarize(@Validated @RequestBody EvidenceCaseRelUpdateSummarizeVO summarizeVO) {
        boolean result = this.superService.updateSummarize(summarizeVO);
        return result ? R.success() : R.fail("修改失败");
    }
}


